
import { MockMethod } from 'vite-plugin-mock'
import pkg from 'mockjs'
const { Random } = pkg

const mentorList = Array.from({ length: 20 }, (_, i) => ({
  mentorId: i + 1,
  name: Random.cname(),
  gender: Random.pick(['男', '女']),
  phone: Random.string('number', 11),
  email: Random.email(),
  organization: Random.pick(['清华大学', '北京大学', '浙江大学']),
  professionalField: Random.pick(['计算机', '人工智能', '数据科学']),
  educationBackground: Random.pick(['博士', '硕士']),
  teamCount: Random.integer(1, 10),
  goodAtStage: Random.pick(['初赛', '复赛', '决赛']),
  status: Random.pick(['空闲', '已分配', '忙碌']),
  taskProgress: Random.pick([null, '50%', '80%']),
  photo: Random.image('100x100'),
  introduction: Random.paragraph(3, 5) // 生成3-5段文字，确保不少于100字
}))

export default [
  // 获取导师列表
  {
    url: '/guide_manage/list',
    method: 'get',
    response: ({ query }) => {
      const { pageNum = 1, pageSize = 10 } = query
      const start = (pageNum - 1) * pageSize
      const end = pageNum * pageSize
      return {
        code: 200,
        message: 'success',
        data: {
          rows: mentorList.slice(start, end),
          total: mentorList.length
        }
      }
    }
  },
  // 获取导师基础信息
  {
    url: '/guide_manage/base/:id',
    method: 'get',
    response: ({ query }) => ({
      code: 200,
      message: 'success',
      data: mentorList.find(item => item.mentorId === +query.id)
    })
  },
  // 获取导师学生列表
  {
    url: '/guide_manage/students/:id',
    method: 'get',
    response: () => ({
      code: 200,
      message: 'success',
      data: [
        { id: 1, name: '张三', team: '创新组', project: '智能机器人', awards: '一等奖' },
        { id: 2, name: '李四', team: '创意组', project: '环保设计', awards: '二等奖' }
      ]
    })
  },
  // 获取导师任务列表
  {
    url: '/guide_manage/tasks/:id',
    method: 'get',
    response: () => ({
      code: 200,
      message: 'success',
      data: [
        { id: 1, name: '项目评审', status: '进行中', deadline: '2023-12-15', description: '评审学生项目方案' },
        { id: 2, name: '团队指导', status: '已完成', deadline: '2023-11-30', description: '每周团队指导会议' }
      ]
    })
  },
  {
    url: '/guide_manage/tasks',
    method: 'post',
    response: (req) => {
      const { mentorId, taskName, description, deadline } = req.body
      return {
        code: 200,
        message: '任务分配成功',
        data: {
          id: Date.now(),
          mentorId,
          name: taskName,
          description,
          deadline,
          status: '待处理',
          createTime: new Date().toISOString()
        }
      }
    }
  },

  // 获取导师沟通记录
  {
    url: '/guide_manage/messages/:id',
    method: 'get',
    response: () => ({
      code: 200,
      message: 'success',
      data: [
        { id: 1, sender: '管理员', time: '2023-12-01 10:00', content: '请尽快完成项目评审' },
        { id: 2, sender: '导师', time: '2023-12-01 11:30', content: '已收到，正在处理' }
      ]
    })
  },
  // 获取导师评价反馈
  {
    url: '/guide_manage/feedbacks/:id',
    method: 'get',
    response: () => ({
      code: 200,
      message: 'success',
      data: [
        { id: 1, student: '张三', rating: 5, content: '导师非常专业，指导很有帮助' },
        { id: 2, student: '李四', rating: 4, content: '导师认真负责，给了很多建议' }
      ]
    })
  },
  // 获取导师能力象限数据
  {
    url: '/guide_manage/abilities/:id',
    method: 'get',
    response: () => ({
      code: 200,
      message: 'success',
      data: {
        technicalAbility: 0.9,
        managementAbility: 0.7,
        communicationAbility: 0.8,
        innovationAbility: 0.85,
        teachingAbility: 0.95,
        researchAbility: 0.88,
        mentoringAbility: 0.92
      }
    })
  },
  // 获取导师详细工作经历
  {
    url: '/guide_manage/experiences/:id',
    method: 'get',
    response: () => ({
      code: 200,
      message: 'success',
      data: [
        {
          id: 1,
          company: '清华大学',
          position: '教授',
          department: '计算机系',
          startDate: '2010-09',
          endDate: '至今',
          description: '主讲机器学习课程，指导研究生科研项目',
          achievements: [
            '发表顶会论文10篇',
            '获得国家自然科学基金资助'
          ]
        },
        {
          id: 2,
          company: '微软亚洲研究院',
          position: '研究员',
          department: '机器学习组',
          startDate: '2005-07',
          endDate: '2010-08',
          description: '从事深度学习算法研究',
          achievements: [
            '开发了新型神经网络架构',
            '获得3项技术专利'
          ]
        }
      ]
    })
  },
  // 获取导师学习经历
  {
    url: '/guide_manage/educations/:id',
    method: 'get',
    response: () => ({
      code: 200,
      message: 'success',
      data: [
        {
          id: 1,
          school: '清华大学',
          degree: '博士',
          major: '计算机科学与技术',
          startDate: '2010-09',
          endDate: '2015-06',
          description: '研究方向：人工智能与机器学习',
          achievements: [
            '发表SCI论文3篇',
            '获得国家奖学金'
          ]
        },
        {
          id: 2,
          school: '北京大学',
          degree: '硕士',
          major: '软件工程',
          startDate: '2007-09',
          endDate: '2010-06',
          description: '研究方向：分布式系统',
          achievements: [
            '参与国家863项目'
          ]
        }
      ]
    })
  },
  // 兼容旧版导师详情接口
  {
    url: '/guide_manage/:id',
    method: 'get',
    response: ({ query }) => ({
      code: 200,
      message: 'success',
      data: mentorList.find(item => item.mentorId === +query.id)
    })
  },
  // 新增导师
  {
    url: '/guide_manage',
    method: 'post',
    response: ({ body }) => {
      const newMentor = {
        mentorId: mentorList.length + 1,
        ...body
      }
      mentorList.unshift(newMentor)
      return {
        code: 200,
        message: '新增成功',
        data: newMentor
      }
    }
  },
  // 修改导师
  {
    url: '/guide_manage',
    method: 'put',
    response: ({ body }) => {
      const index = mentorList.findIndex(item => item.mentorId === body.mentorId)
      if (index !== -1) mentorList[index] = { ...mentorList[index], ...body }
      return { code: 200, message: '修改成功' }
    }
  },
  // 删除导师
  {
    url: '/guide_manage/:id',
    method: 'delete',
    response: ({ query }) => {
      const index = mentorList.findIndex(item => item.mentorId === +query.id)
      if (index !== -1) mentorList.splice(index, 1)
      return { code: 200, message: '删除成功' }
    }
  },
  // 发送消息
  {
    url: '/guide_manage/messages',
    method: 'post',
    response: ({ body }) => {
      const { mentorId, content } = body
      const newMessage = {
        id: Date.now(),
        sender: '我',
        time: new Date().toISOString(),
        content
      }
      return {
        code: 200,
        message: '发送成功',
        data: newMessage
      }
    }
  },
  // 删除消息
  {
    url: '/guide_manage/messages/:id',
    method: 'delete',
    response: ({ query }) => {
      return {
        code: 200,
        message: '删除成功',
        data: query.id
      }
    }
  }
] as MockMethod[]
